package cc.mrbird.tram.service.impl;

import cc.mrbird.submission.domain.PullDown;
import cc.mrbird.tram.dao.TramMapper;
import cc.mrbird.tram.domain.Tram;
import cc.mrbird.tram.service.TramService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TramServiceImpl implements TramService {
    @Autowired
    private TramMapper tramMapper;
    @Override
    public void saveTram(Tram tram) {
        tramMapper.saveTram(tram);
    }

    @Override
    public String findId() {
        return tramMapper.findId();
    }

    @Override
    public List<Tram> getTramList(Tram tram) {
        return tramMapper.getTramList(tram);
    }

    @Override
    public List<PullDown> FindPullDown(PullDown pullDown) {
        return tramMapper.FindPullDown(pullDown);
    }

    @Override
    public PullDown savePullDown(PullDown pullDown) {
        return tramMapper.savePullDown(pullDown);
    }

    @Override
    public void addPullDown(PullDown pullDown) {
        tramMapper.addPullDown(pullDown);
    }

    @Override
    public String sumFirst() {
        return tramMapper.sumFirst();
    }

    @Override
    public Tram getTramId(Tram tram) {
        List<Tram> list = tramMapper.getTramList(tram);
        if (list == null || list.size()==0){
            return null;
        }
        for(Tram tram1:list){
            String processingResults = tram1.getProcessingResults();
            if(processingResults == null){
                tram1.setProcessingResults("");
            }
            String complaintType = tram1.getComplaintType();
            if(complaintType == null){
                tram1.setComplaintType("");
            }
            String handler = tram1.getHandler();
            if(handler == null){
                tram1.setHandler("");
            }
            String processing = tram1.getProcessing();
            if(processing == null){
                tram1.setProcessing("");
            }
        }
        return list.get(0);
    }

    @Override
    public void updateTram(Tram tram) {
        tramMapper.updateTram(tram);
    }

    @Override
    public void cancelTram(Tram tram) {
        tramMapper.cancelTram(tram);
    }
}
